/*
 * Copyright 2016-2022 dromara.org.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.dromara.mendmix.mybatis.logging;

import org.apache.ibatis.logging.Log;
import org.dromara.mendmix.common.CurrentRuntimeContext;
import org.dromara.mendmix.logging.applog.LogFormater;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @description <br>
 * @author <a href="mailto:vakinge@gmail.com">jiangwei</a>
 * @date 2025年5月18日
 */
public class DyncLevelLog implements Log {

	private final Logger logger;

    public DyncLevelLog(String clazz) {
        this.logger = LoggerFactory.getLogger(clazz);
    }
    
	@Override
	public boolean isDebugEnabled() {
		return logger.isDebugEnabled() || CurrentRuntimeContext.isDebugMode();
	}

	@Override
	public boolean isTraceEnabled() {
		return logger.isTraceEnabled() || CurrentRuntimeContext.isDebugMode();
	}
	
	@Override
	public void error(String s, Throwable e) {
		logger.error(s, e);
	}

	@Override
	public void error(String s) {
		logger.error(s);
	}

	@Override
	public void debug(String s) {
		if(CurrentRuntimeContext.isDebugMode()) {
			logger.info(LogFormater.buildTraceLogHeader() + s);
		}else {
			logger.debug(s);
		}
	}

	@Override
	public void trace(String s) {
		if(CurrentRuntimeContext.isDebugMode()) {
			logger.info(LogFormater.buildTraceLogHeader() + s);
		}else {
			logger.trace(s);
		}
	}

	@Override
	public void warn(String s) {
		logger.warn(s);
	}

}
